﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
namespace HealthSystem.sysAdmin
{
    public partial class MergeDetail : BasePage
    {
        HW_SchoolManager schoolManager = new HW_SchoolManager();
        HW_SchoolMergeLogManager mergeManager = new HW_SchoolMergeLogManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDetail();
                BindGrid();
            }
        }
        private void BindDetail()
        {
            string schoolcode = Request["schoolcode"] as string;
            var school= schoolManager.GetById(schoolcode);
            if (school == null)
            {
                ExtAspNet.Alert.Show("该学校可能已经被删除，请确认!");
                return;
            }
            TextBox1.Text = school.DistrictName == null ? "" : school.DistrictName;
            SchoolName.Text = school.Name;
            permitcheck.Checked = school.Permit.Value;
            Address.Text = school.Address;
            LinkMan.Text = school.LinkMan;
            OfficePhone.Text = school.OfficePhone;
            MobilePhone.Text = school.MobilePhone;
            Email.Text = school.Email;
            SchoolType.Text = school.SchoolType;
            OrgName.Text = school.OrgCode == null ? "" : school.OrgCode;

        }
        private void BindGrid()
        {
            string schoolcode = Request["schoolcode"] as string;
            var dt= mergeManager.GetByNewSchoolId(schoolcode);
            grid2.DataSource = dt;
            grid2.DataBind();
        }
        protected void DeMerge(object sender,EventArgs e)
        {
            try
            {
                string schoolcode = Request["schoolcode"] as string;
                mergeManager.DeMerge(schoolcode);
                ExtAspNet.PageContext.RegisterStartupScript(ExtAspNet.ActiveWindow.GetHidePostBackReference());
            }
            catch (Exception ex)
            {
                ExtAspNet.Alert.Show(ex.Message);
            }
        }
    }
}